from time import sleep

from selenium.webdriver.common.by import By

from Common.Utils import BlogDriver


class Login:
    url=""
    driver=""
    def __init__(self):
        self.url="http://127.0.0.1:58080/sign-in.html"
        self.driver=BlogDriver.driver
        self.driver.get(self.url)


    def FaiLogin(self):

        password_field=self.driver.find_element(By.CSS_SELECTOR, "#password")
        self.driver.execute_script("arguments[0].type='text';", password_field)
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("小ming")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        BlogDriver.getScreenshort()

        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        BlogDriver.getScreenshort()

        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("小小ming")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        BlogDriver.getScreenshort()
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()




    def SucLogin(self):

        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("小ming")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        sleep(2)
        BlogDriver.getScreenshort()
